<% var js = { %>
<script>
	$(function() {
		function loadData(){
			var search={"key":$("#txtKey").val()};
			$Y.grid({
				id:'table',
				obj:'page',
				search:search,
				checkbox:false,
				rownumber:true,
				size:10,
				pagesize:[10,20,50],
				index:1,
				pager:"page",
				key:"id",
				columns: [
		            {
		                field: "id",
		                title: "ID",
		                hidden:true
		            },
		            {
		                field: "name",
		                title: "模板名称"
		            },
		            {
		                field: "code",
		                title: "模板代码"
		            },
		            {
		                field: "typename",
		                title: "模板类别"
		            },
		            {
		                field: "url",
		                title: "路径"
		            },
		            {
		                field: "time",
		                title: "创建时间"
		            },
		            {
		                field: "author",
		                title: "创建人"
		            },
		            {
		                field: "seq",
		                title: "显示顺序"
		            },
		            {
		                field: "status",
		                title: "状态",
		                formatter: function (v) {
		                    return v ? "启用" : "锁定";
		                }
		            }
				]
			});
		}
		loadData();
		$("#btnAdd").click(function() {
			core.frame({
				title:'新增',
				btns:[ '确认', '取消' ],
				area:[ '580px', '500px' ],
				url:'detail',
				success:function(index, layero){
					var form=layer.getChildFrame('form', index);
					if(form.find("#type_id").val()=="0"){
						layer.tips('请选择模板类别', form.find('#type_id'));
						return false;
					}
					if(form.find("#name").val()==""){
						layer.tips('名称不能为空', form.find('#account'));
						form.find("#name").focus();
						return false;
					}
					if(form.find("#url").val()==""){
						layer.tips('访问链接不能为空', form.find('#url'));
						form.find("#url").focus();
						return false;
					}
					if(form.find("#url").val()==""){
						layer.tips('访问链接不能为空', form.find('#url'));
						form.find("#url").focus();
						return false;
					}
					var model={"id":form.find("#id").val()};
					model.name=form.find("#name").val();
					model.code=form.find("#code").val();
					model.status=form.find("#status").val();
					model.url=form.find("#url").val();
					model.type_id=form.find("#type_id").val();
					model.seq=form.find("#seq").val();
					model.author=form.find("#author").val();
					var loadIndex = layer.load();//加载层
					$.post("save",model,function(result){
						layer.close(loadIndex);
						if(result.flag){
							layer.alert("新增成功");
							loadData();
							layer.close(index);
						}else{
							layer.alert(result.msg==null?"新增失败":result.msg);
						}
					});
				}
			});
		});
		$("#btnUpdate").click(function() {
			var ids=$Y.getSelectIds("table");
			if(ids.length==0){
				layer.alert("请选择要修改的数据");
				return false;
			}
			if(ids.length>1){
				layer.alert("只能选择一条数据修改");
				return false;
			}
			core.frame({
				title:'修改',
				btns:[ '确认', '取消' ],
				area:[ '480px', '400px' ],
				url:'detail?id='+ids[0],
				success:function(index, layero){
					var form=layer.getChildFrame('form', index);
					if(form.find("#type_id").val()=="0"){
						layer.tips('请选择模板类别', form.find('#type_id'));
						return false;
					}
					if(form.find("#name").val()==""){
						layer.tips('名称不能为空', form.find('#account'));
						form.find("#name").focus();
						return false;
					}
					if(form.find("#url").val()==""){
						layer.tips('访问链接不能为空', form.find('#url'));
						form.find("#url").focus();
						return false;
					}
					if(form.find("#url").val()==""){
						layer.tips('访问链接不能为空', form.find('#url'));
						form.find("#url").focus();
						return false;
					}
					var model={"id":form.find("#id").val()};
					model.name=form.find("#name").val();
					model.code=form.find("#code").val();
					model.status=form.find("#status").val();
					model.url=form.find("#url").val();
					model.type_id=form.find("#type_id").val();
					model.seq=form.find("#seq").val();
					model.author=form.find("#author").val();
					var loadIndex = layer.load();//加载层
					$.post("save",model,function(result){
						layer.close(loadIndex);
						if(result.flag){
							layer.alert("修改成功");
							loadData();
							layer.close(index);
						}else{
							layer.alert(result.msg==null?"修改失败":result.msg);
						}
					});
				}
			});
		});
		$("#btnRefresh").click(function() {
			loadData();
		});
		$("#btnSearch").click(function() {
			loadData();
		});
		$("#btnDelete").click(function() {
			layer.confirm('删除后不能恢复，确认删除？', {icon: 3, title:'提示'}, function(index){
				var ids=$Y.getSelectIds("table");
				if(ids.length==0){
					layer.alert("请选择要删除的数据");
				}else{
					var loadIndex = layer.load();//加载层
					$.post("delete",{"ids":ids},function(result){
						layer.close(loadIndex);
						if(result.flag){
							layer.alert("删除成功");
							loadData();
						}else{
							layer.alert(result.msg==null?"删除失败":result.msg);
						}
					});
				}
				layer.close(index);
			});
		});
	});
</script>
<% }; %> 
<% layout("/beetl/common/_layout.html",{title:"菜单管理",js:js}){%>
<link href="../css/admin.css" rel="stylesheet" />
<div class="main-container">
	<div class="box box-default box-radius">
		<div class="box-head">
			菜单名称： <input id="txtKey" type="text" class="form-input" placeholder="菜单名称" />
			<button id="btnSearch" class="btn btn-bg-green">搜索</button>
			<button id="btnRefresh" class="btn btn-bg-green">刷新</button>
			<button id="btnAdd" class="btn btn-bg-green">新增</button>
			<button id="btnUpdate" class="btn btn-bg-green">修改</button>
			<button id="btnDelete" class="btn btn-bg-red">删除</button>
			<button id="btnButton" class="btn btn-bg-green">按钮管理</button>
		</div>
		<table id="table" class="box-body"></table>
		<div class="box-foot">
			<div id="page" class="box-footer"></div>
		</div>
	</div>
</div>
<% } %>








